import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/index.vue'),
    meta: { title: '登录' }
  },
  {
    path: '/student',
    component: () => import('../layout/student/index.vue'),
    redirect: '/student/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'StudentDashboard',
        component: () => import('../views/student/dashboard/index.vue'),
        meta: { title: '学生首页' }
      },
      {
        path: 'services',
        name: 'StudentServices',
        component: () => import('../views/student/services/index.vue'),
        meta: { title: '服务中心' }
      },
      {
        path: 'course-selection',
        name: 'CourseSelection',
        component: () => import('../views/student/course-selection/index.vue'),
        meta: { title: '选课管理' }
      },
      {
        path: 'schedule',
        name: 'Schedule',
        component: () => import('../views/student/schedule/index.vue'),
        meta: { title: '课表查看' }
      },
      {
        path: 'attendance',
        name: 'Attendance',
        component: () => import('../views/student/attendance/index.vue'),
        meta: { title: '签到管理' }
      },
      {
        path: 'homework',
        name: 'Homework',
        component: () => import('../views/student/homework/index.vue'),
        meta: { title: '作业管理' }
      },
      {
        path: 'homework/detail/:id',
        name: 'HomeworkDetail',
        component: () => import('../views/student/homework/detail.vue'),
        meta: { title: '作业详情' }
      },
      {
        path: 'leave',
        name: 'Leave',
        component: () => import('../views/student/leave/index.vue'),
        meta: { title: '请假申请' }
      },
      {
        path: 'resources',
        name: 'Resources',
        component: () => import('../views/student/resources/index.vue'),
        meta: { title: '下载资料' }
      },
      {
        path: 'grades',
        name: 'Grades',
        component: () => import('../views/student/grades/index.vue'),
        meta: { title: '成绩查询' }
      },
      {
        path: 'credits',
        name: 'Credits',
        component: () => import('../views/student/credits/index.vue'),
        meta: { title: '学分查询' }
      },
      {
        path: 'evaluation',
        name: 'Evaluation',
        component: () => import('../views/student/evaluation/index.vue'),
        meta: { title: '教学评价' }
      },
      {
        path: 'learning-path',
        name: 'LearningPath',
        component: () => import('../views/student/learning-path/index.vue'),
        meta: { title: '学习路线' }
      },
      {
        path: 'recommended-courses',
        name: 'RecommendedCourses',
        component: () => import('../views/student/recommended-courses/index.vue'),
        meta: { title: '推荐课程' }
      },
      {
        path: 'profile',
        name: 'StudentProfile',
        component: () => import('../views/profile/index.vue'),
        meta: { title: '个人信息' }
      }
    ]
  },
  {
    path: '/teacher',
    component: () => import('../layout/teacher/index.vue'),
    redirect: '/teacher/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'TeacherDashboard',
        component: () => import('../views/teacher/dashboard/index.vue'),
        meta: { title: '教师首页' }
      },
      {
        path: 'profile',
        name: 'TeacherProfile',
        component: () => import('../views/profile/index.vue'),
        meta: { title: '个人信息' }
      }
    ]
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('../views/error/404.vue'),
    meta: { title: '404' }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - Smart Campus` : 'Smart Campus'
  next()
})

export default router 